import random
import time
class ship:
    def __init__(self, health = 100, xpos = random.randint(25, 75), toggleFire = False, score = 0):
        self.health = health
        self.toggleFire = toggleFire
        self.xpos = xpos
        self.score = score
        self.direction = -1
        self.lastFire = time.time()

    def hit(self, damage):
        self.health -= damage

    def setFireState(self, newState):
        self.toggleFire = newState

    def getFireState(self):
        return self.toggleFire

    def getLastFire(self):
        if time.time() < self.lastFire + 0.12:
            return False
        else:
            self.lastFire = time.time()
            return True

    def setDirection(self, direction):
        self.direction = direction

    def getDirection(self):
        return self.direction

    def move(self):
        #move in the specified direction, 1 right, 0 left, only if moving will stay inside the 100 digit possibility
        if self.direction == 1 and self.xpos < 100:
            self.xpos += 1
            return True
        elif self.direction == 0 and self.xpos > 0:
            self.xpos -= 1
            return True
        else:
            return False

    def getxpos(self):
        return self.xpos

    def getHealth(self):
        return self.health

    def setHealth(self, newHealth):
        self.health = newHealth

    def getScore(self):
        return self.score

    def setScore(self, score):
        self.score += score

    def resetScore(self):
        self.score = 0


